﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections;

namespace TaxonomyReader
{
    #region XSD
    [Serializable]
    public class ImportBO
    {
        //imported schemas path namespace 
        public string Namespace { get; set; }
        public string SchemaLocation { get; set; }
        public string ActualPath { get; set; }
    }

    [Serializable]
    public class RoleTypeBO
    {
        //
        public string RoleUri { get; set; }
        public string Id { get; set; }
        public string Definition { get; set; }
        public List<LinkBaseType> LinkUsedOn { get; set; }
    }

    [Serializable]
    public class LinkBaseRefBO
    {
        public string Href { get; set; }
        public string ActualPath { get; set; }
        public XLinkType LinkType { get; set; }
        public LinkBaseType LinkBaseType { get; set; }
        public ArcRole ArcRole { get; set; }
    }

    [Serializable]
    public class ElementBO
    {
        //for reference textbox wont be serialized
        [CategoryAttribute("Taxonomy Element")]
        public string Name { get; set; }
        [CategoryAttribute("Taxonomy Element")]
        public string Id { get; set; }
        [CategoryAttribute("Taxonomy Element")]
        public bool IsAbstract { get; set; }
        [CategoryAttribute("Taxonomy Element")]
        public XsdSubstitutionGroup SubstitutionGroup { get; set; }
        [CategoryAttribute("Taxonomy Element")]
        [DisplayName("Base Type")]
        public XsdType Type { get; set; }
        [CategoryAttribute("Taxonomy Element")]
        public string DefinedType { get; set; }
        [Browsable(false)]
        public string Type_str { get; set; }
        [CategoryAttribute("Taxonomy Element")]
        public XsdPeriodType PeriodType { get; set; }
        [CategoryAttribute("Taxonomy Element")]
        public XsdBalance Balance { get; set; }
        [CategoryAttribute("Taxonomy Element")]
        public bool Nillable { get; set; }

        public ElementBO()
        {
            this.DefinedType = "";
        }
    }

    [Serializable]
    public class ComplexType
    {
        public string name;
        public string baseType;
        public string restriction;
    }

    [Serializable]
    public class XsdBO
    {
        public string targetNamespace { get; set; }
        public List<ImportBO> Imports { get; set; }
        public List<RoleTypeBO> RoleTypes { get; set; }
        public List<LinkBaseRefBO> LinkbaseRefs { get; set; }
        public List<ElementBO> Elements { get; set; }

        public List<ComplexType> ComplexTypes { get; set; }
        public List<string> Namespaces { get; set; }

        //making these lists for the property grid
        public List<DefinitonLinkbaseBO> DefLink { get; set; }
        public List<PresentationLinkbaseBO> PresLink { get; set; }
        public List<CalculationLinkbaseBO> CalcLink { get; set; }
        public List<LabelLinkbaseBO> LabLink { get; set; }

        public List<XsdBO> ImportedXsds { get; set; }

        public bool HasError { get; set; }
        public XsdError XsdErrors { get; set; }

        public string ActualSchemaPath { get; set; }
        public string XsdName { get; set; }
    }

    [Serializable]
    public class XsdError
    {
        public string fileInvalid { get; set; }
        public string fileDownloadFailed { get; set; }
        public string fileNotFound { get; set; }
        public List<string> UndefinedLabels { get; set; } 
    }

 

    #endregion
 
    #region Definition Linkbase
    [Serializable]
    [DescriptionAttribute("Primary element on which hypercube is defined in DefinitionLinkbase")]
    public class HycElement
    {
        public string Id_Href { get; set; }
        public string Id_Title { get; set; }
        public string Id_Label { get; set; }
        //public Loc Id { get; set; }
        public string Use { get; set; }
        public double Order { get; set; }

        [Browsable(false)]
        public List<HycElement> Children { get; set; }
    }

    [Serializable]
    [DescriptionAttribute("Dimension Domains which are contained in the hypercube")]
    public class HycDimension
    {
        public string Dimension_Href { get; set; }
        public string Dimension_Title { get; set; }
        public string Dimension_Label { get; set; }

        public ArcRole ArcRole { get; set; }

        public List<HycDomain> Domains { get; set; }
 
    }

    [Serializable]
    public class HycDomain
    {
        public string Domain_Href { get; set; }
        public string Domain_Title { get; set; }
        public string Domain_Label { get; set; }

        public ArcRole ArcRole { get; set; }

        public List<HycDomain> ChildDomains { get; set; }
    }
 
    [Serializable]
    public class HyperCubeBO  //:Locator
    {
        public string Hypercube_Href { get; set; }
        public string Hypercube_Title { get; set; }
        public string Hypercube_Label { get; set; }

        public string HypercubeDefinedOn { get; set; }
        public HycElement HycPrimElement { get; set; }
        public List<HycDimension> Dimensions { get; set; }
        public ContextElement ContextElement { get; set; }
        public ArcRole ArcRole { get; set; }
    }

    [Serializable]
    public class DefinitionLinkBO
    {
        public string Href { get; set; }
        public string ExtendedLinkRole { get; set; }
        public List<HycDimension> DefaultDimensions { get; set; }
        public List<HycDimension> DomainsWithoutMembers { get; set; }
        public List<HyperCubeBO> HyperCubes { get; set; }
    }

    [Serializable]
    public class DefinitonLinkbaseBO
    {
        public string Href { get; set; }
        public string LinkBaseName { get; set; }
        public List<DefinitionLinkBO> DefintionLinks { get; set; }
    }
    #endregion

    #region Presentation Linkbase
    [Serializable]
    [DescriptionAttribute("Define parent-child relation between two elements")]
    public class PresentationBO
    {
        [Browsable(false)]
        public ArcRole ArcRole { get; set; }

        [CategoryAttribute("Presentation Arc Element")]
        [DisplayName("Href")]
        public string Element_Href { get; set; }

        [Browsable(false)]
        public string Element_Title { get; set; }

        [CategoryAttribute("Presentation Arc Element")]
        [DisplayName("Label")]
        public string Element_Label { get; set; }

        //public Loc Element { get; set; }

        [Browsable(false)]
        public List<PresentationBO> Children { get; set; }

        [CategoryAttribute("Presentation Arc Element")]
        [DisplayName("Title")]
        public string Title { get; set; }

        [CategoryAttribute("Presentation Arc Element")]
        [DisplayName("Order")]
        /// <summary>
        /// defined for ToElement
        /// </summary>
        public double Order { get; set; }

        [Browsable(false)]
        /// <summary>
        /// defined for ToElement
        /// </summary>
        public string Show { get; set; }

        [CategoryAttribute("Presentation Arc Element")]
        [DisplayName("Label Role")]
        /// <summary>
        /// defined for ToElement
        /// </summary>
        public string PreferredLabelRole { get; set; }

        [CategoryAttribute("Presentation Arc Element")]
        [DisplayName("Labels Availabe")]
        public List<LabelBO> PresentationLabel { get; set; }

        [CategoryAttribute("Presentation Arc Element")]
        [DisplayName("Preferred Label")]
        public string PreferredLabel { get; set; }

        [Browsable(false)]
        public ElementBO TaxonomyElement { get; set; }

        private string GetPreferredLabel()
        {
            foreach (LabelBO lab1 in this.PresentationLabel)
            {
                if (lab1.LabelRole == this.PreferredLabelRole)
                    return lab1.Label;
            }

            return null;
        }
    }

    //this will have dimension, domains,hypercube and primary elements
    [Serializable]
    public class PresentationLinkBO
    {
        public string Href { get; set; }
        public string ExtendedLinkRole { get; set; }
        [Browsable(false)]
        public List<PresentationBO> Presentations { get; set; }
    }

    [Serializable]
    public class PresentationLinkbaseBO
    {
        public string Href { get; set; }
        public string LinkBaseName { get; set; }
        [Browsable(false)]
        public List<PresentationLinkBO> PresentationLinks { get; set; }
    }
    #endregion

    #region Calculation Linkbase
    [Serializable]
    [DescriptionAttribute("Define summation-item relation between two elements")]
    public class CalculationBO
    {
        [Browsable(false)]
        public ArcRole ArcRole { get; set; }

        [CategoryAttribute("Calculation Arc Element")]
        [DisplayName("Href")]
        public string Element_Href { get; set; }

        [Browsable(false)]
        public string Element_Title { get; set; }

        [CategoryAttribute("Calculation Arc Element")]
        [DisplayName("Label")]
        public string Element_Label { get; set; }

        //public Loc Element { get; set; }

        [Browsable(false)]
        public List<CalculationBO> Children { get; set; }

        [CategoryAttribute("Calculation Arc Element")]
        [DisplayName("Title")]
        public string Title { get; set; }

        [CategoryAttribute("Calculation Arc Element")]
        [DisplayName("Order")]
        /// <summary>
        /// defined for ToElement
        /// </summary>
        public double Order { get; set; }

        [Browsable(false)]
        /// <summary>
        /// defined for ToElement
        /// </summary>
        public string Show { get; set; }

        [CategoryAttribute("Calculation Arc Element")]
        [DisplayName("Weight")]
        /// <summary>
        /// defined for ToElement
        /// </summary>
        public double Weight { get; set; }
    }

    //this will have only primary elements
    [Serializable]
    public class CalculationLinkBO
    {
        public string Href { get; set; }
        public string ExtendedLinkRole { get; set; }
        public List<CalculationBO> Calculations { get; set; }
    }

    [Serializable]
    public class CalculationLinkbaseBO
    {
        public string Href { get; set; }
        public string LinkBaseName { get; set; }
        public List<CalculationLinkBO> CalculationLinks { get; set; }
    }
    #endregion

    #region Label Linkbase
    [Serializable]
    public class LabelBO
    {
        //not using Loc datatype as label locator has only HRef
        //public Loc Loc { get; set; }
        public string Href { get; set; }
        public ArcRole ArcRole { get; set; }
        public string LabelRole { get; set; }
        public string Language { get; set; }
        public string Label { get; set; }
        public string LabelId { get; set; }
        public ArcUse Use { get; set; }
    }

    [Serializable]
    public class LabelLinkbaseBO
    {
        public string Href { get; set; }
        public string LinkBaseName { get; set; }
        public List<LabelBO> Labels { get; set; }
    }
    #endregion

}
